#ifndef UDP_MANAGER_H
#define UDP_MANAGER_H

#include <string>
#include <sys/socket.h>
#include <netdb.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#include <esp_log.h>
#include <functional>

namespace app
{
    class udpPort
    {
    public:
        udpPort(int local_port = 4210, int broadcast_port = 12345) : local_port(local_port), broadcast_port(broadcast_port) {};
        void start();

        void onReceive(std::function<void(const char *, size_t)> callback)
        {
            on_receive = callback;
        }

        int send(const char *data, size_t len);
        int send(const std::string &str);

    private:
        int local_port;
        int broadcast_port;
        int sock;

        struct sockaddr_in broadcast_addr;
        std::function<void(const char *, size_t)> on_receive;
    };
};
#endif
